#!/bin/bash
#
# Init file for the flashpolicy server daemon
#
# chkconfig: 2345 20 20
# description: Starts a server on port 843 to server flash policy requests
#
# processname: flashpolicyd.rb

# Source function library.
. /etc/rc.d/init.d/functions

desc="Flash policy server"
prog="flashpolicyd"

# these can be overrode in /etc/sysconfig/flashpolicyd
RETVAL=0
TIMEOUT=10
XML=/etc/flashpolicy.xml
LOGFREQ=1800
LOGFILE=/var/log/flashpolicyd.log
USER=root
BINDIR=/usr/sbin
PORT=843

if [ -r /etc/sysconfig/$prog ]; then
	source /etc/sysconfig/$prog
fi

start() {
	echo -n $"Starting $desc ($prog): "
	daemon --check=$prog ${BINDIR}/${prog} --timeout=${TIMEOUT} --xml=${XML} --logfreq=${LOGFREQ} --logfile=${LOGFILE} --user=${USER} --port=${PORT}
	RETVAL=$?
	echo 
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
	return $RETVAL
}

stop() {
	echo -n $"Stopping $desc ($prog): "
	killproc $prog
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
	return $RETVAL
}

restart() {
  	stop
	start
}

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
  	restart
	;;
  condrestart)
	[ -e /var/lock/subsys/$prog ] && restart
	RETVAL=$?
	;;
  status)
	status $prog
	RETVAL=$?
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|condrestart|status}"
	RETVAL=1
esac

exit $RETVAL
